import threading
import time


class MyThread(threading.Thread):
    def __init__(self, threadID, name, counter):
        threading.Thread.__init__(self=self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
        pass

    def run(self):
        print('======start {}'.format(self.name))
        print_time(self.name, self.counter, 1)
        print('======end {}'.format(self.name))
        pass


exitFlag = 0


def print_time(thread_name, counter, delay):
    while counter:
        if exitFlag:
            print(delay)
        time.sleep(delay)
        print(time.strftime('%Y-%m-%d', time.localtime()))
        print('线程名称：{}'.format(thread_name))
        counter -= 1


t1 = MyThread('0001', 'test1', 4)
t2 = MyThread('0002', 'test2', 2)
t1.start()
t2.start()
